What is @turf/area?
@turf/area is a module from the Turf.js library that allows you to calculate the area of GeoJSON polygons. It is useful for geospatial analysis and can handle complex polygons, including those with holes.
Calculate area of a simple polygon
This feature allows you to calculate the area of a simple polygon. The code sample demonstrates how to create a polygon and calculate its area using the @turf/area module.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-74.0059413, 40.7127837],
[-73.935242, 40.730610],
[-73.944158, 40.678178],
[-74.0059413, 40.7127837]
]]);
const area = turf.area(polygon);
console.log(area);
Calculate area of a polygon with holes
This feature allows you to calculate the area of a polygon that contains holes. The code sample demonstrates how to create such a polygon and calculate its area using the @turf/area module.
const turf = require('@turf/turf');
const polygonWithHole = turf.polygon([[
[-74.0059413, 40.7127837],
[-73.935242, 40.730610],
[-73.944158, 40.678178],
[-74.0059413, 40.7127837]
], [
[-73.965242, 40.7127837],
[-73.955242, 40.7227837],
[-73.945242, 40.7127837],
[-73.965242, 40.7127837]
]]);
const area = turf.area(polygonWithHole);
console.log(area);